class Solution:
    def findKDistantIndices(self, nums: list, key: int, k: int) -> list:
        s = set()
        for i in range(len(nums)):
            if nums[i] == key:
                for j in range(i-k, i+k+1):
                    if j < 0:
                        continue
                    if j >= len(nums):
                        continue
                    s.add(j)
        res = []
        for i in range(len(nums)):
            if i in s:
                res.append(i)

        return res
